package com.jyw.business.knowledge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jyw.common.core.domain.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.AjaxResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.business.knowledge.domain.KlKnowledge;
import com.jyw.business.knowledge.service.IKlKnowledgeService;
import com.jyw.common.utils.poi.ExcelUtil;
import com.jyw.common.core.page.TableDataInfo;

/**
 * 知识库-信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/knowledge/knowledge")
@Api(tags = "知识库管理")
public class KlKnowledgeController extends BaseController
{
    @Autowired
    private IKlKnowledgeService klKnowledgeService;

    /**
     * 查询知识库-信息列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:knowledge:list')")
    @GetMapping("/list")
    @ApiOperation("知识库查询")
    public TableDataInfo<KlKnowledge> list(KlKnowledge klKnowledge)
    {
        startPage();
        List<KlKnowledge> list = klKnowledgeService.selectKlKnowledgeList(klKnowledge);
        return getDataTable(list);
    }

    /**
     * 获取知识库-信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:knowledge:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("知识库详情")
    public CommonResult<KlKnowledge> getInfo(@PathVariable("id") Long id)
    {
        return CommonResult.success(klKnowledgeService.selectKlKnowledgeById(id));
    }

    /**
     * 新增知识库-信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:knowledge:add')")
    @Log(title = "知识库-信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("知识库新增")
    public CommonResult add(@RequestBody KlKnowledge klKnowledge)
    {
        return CommonResult.success(klKnowledgeService.insertKlKnowledge(klKnowledge));
    }

    /**
     * 修改知识库-信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:knowledge:edit')")
    @Log(title = "知识库-信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("知识库编辑")
    public CommonResult edit(@RequestBody KlKnowledge klKnowledge)
    {
        return CommonResult.success(klKnowledgeService.updateKlKnowledge(klKnowledge));
    }

    /**
     * 删除知识库-信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:knowledge:remove')")
    @Log(title = "知识库-信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return CommonResult.success(klKnowledgeService.deleteKlKnowledgeByIds(ids));
    }
}
